#ifndef __LOAD_BALANCE_STRATEGY_H__
#define __LOAD_BALANCE_STRATEGY_H__

#include <map>
#include <string>
#include <vector>
#include <functional>
#include <cstdint>

class SubReactor;

// 负载均衡策略枚举
enum class LoadBalanceStrategy {
    ROUND_ROBIN,        // 轮询
    LEAST_CONNECTIONS,  // 最少连接
    CONSISTENT_HASH,    // 一致性哈希
    ADAPTIVE           // 自适应混合策略
};

// 一致性哈希实现
class ConsistentHash {
private:
    std::map<uint32_t, SubReactor*> _ring;  // 哈希环
    static constexpr int VIRTUAL_NODES = 150; // 每个真实节点的虚拟节点数
    
public:
    void addReactor(SubReactor* reactor, int reactorId);
    void removeReactor(int reactorId);
    SubReactor* getReactor(const std::string& clientIP);
    void clear();
    
private:
    uint32_t hashFunction(const std::string& key);
};

#endif